package site.marqstree.kotlin.library.base.ui.widget.search

import android.content.Context
import android.util.AttributeSet
import android.view.View
import android.widget.FrameLayout
import kotlinx.android.synthetic.main.search_text.view.*
import org.jetbrains.anko.startActivity
import site.marqstree.kotlin.library.base.ui.R
import site.marqstree.kotlin.library.base.ui.widget.search.activity.ActivitySearch


/*
 * 项目名: KotlinMall
 * 包名: site.marqstree.kotlin.library.base.ui.widget.search
 * 文件名: SearchTextView
 * 创建者: marqstree
 * 创建时间: 2020/3/9 15:19
 * 描述: TODO
 */

//@JvmOverloads这个注解相当于声明了三个构造函数
class SearchTextView @JvmOverloads constructor(
    context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : FrameLayout(context, attrs, defStyleAttr) {

    private var searchText:String = "search"

    init {
        val typedArray = context.obtainStyledAttributes(attrs, R.styleable.SearchTextView)

        searchText = typedArray.getString(R.styleable.SearchTextView_searchText)?:"search"

        typedArray.recycle()

        initView()
    }

    private fun initView() {
        View.inflate(context, R.layout.search_text,this)

        searchText.let{
            mSearchTv.text = "{fa-search}"+" "+it
        }

        mSearchTv.setOnClickListener{
            context.startActivity<ActivitySearch>()
        }
    }

}